ArcPy and ArcGIS - Second Edition by Silas Toms & Dara O’Beirne
Author:Silas Toms & Dara O’Beirne [Toms, Silas]
Language: eng
Format: azw3
Publisher: Packt Publishing
Published: 2017-08-04T04:00:00+00:00
Adding dynamic components to the script
To start making the script into a script tool, we should first copy the script that we created in Chapter 4, ArcPy Geometry Objects and Cursors, Chapter4_1.py as Chapter5_1.py in a new folder called Chapter5. We can then start replacing the hard-coded variables with dynamic variables using arcpy.GetParameterAsText. There is another ArcPy method called GetParameter, which accepts the inputs as an object, but, for our purpose, we need to use GetParameterAsText.
By adding arcpy.GetParameterAsText and arcpy.AddMessage to the script, we will take the first step towards creating a script tool. Care must be taken to ensure that the variables created from the dynamic parameters are in the correct order, as reordering them can be time consuming. Once the parameters are added to the script, and hard-coded portions of the script are replaced with variables, the script is ready to become a script tool.
First, move all of the variables that are hard-coded to the top of the script. Then, replace all of the assigned values with arcpy.GetParameterAsText, making them dynamic values. Each parameter is referred to using zero-based indexing; however, they are passed to a function individually instead of as a member of a list, as shown next:
#Chapter 5_ScriptTool.py
import arcpy, csv
busStops = arcpy.GetParameterAsText(0)
censusBlocks2010 = arcpy.GetParameterAsText(1)
censusBlockField = arcpy.GetParameterAsText(2)
csvname = arcpy.GetParameterAsText(3)
headers = arcpy.GetParameterAsText(4).split(',')
sql = arcpy.GetParameterAsText(5)
keyfields = arcpy.GetParameterAsText(6).split(';')
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
The Mikado Method by Ola Ellnestam Daniel Brolund(26274)
Hello! Python by Anthony Briggs(25203)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(24432)
Kotlin in Action by Dmitry Jemerov(23522)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(22868)
Dependency Injection in .NET by Mark Seemann(22655)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(21419)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(20255)
Grails in Action by Glen Smith Peter Ledbrook(19329)
Adobe Camera Raw For Digital Photographers Only by Rob Sheppard(17044)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(16355)
Secrets of the JavaScript Ninja by John Resig & Bear Bibeault(14070)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(12244)
Jquery UI in Action : Master the concepts Of Jquery UI: A Step By Step Approach by ANMOL GOYAL(11519)
A Developer's Guide to Building Resilient Cloud Applications with Azure by Hamida Rebai Trabelsi(10635)
Hit Refresh by Satya Nadella(9209)
The Kubernetes Operator Framework Book by Michael Dame(8573)
Exploring Deepfakes by Bryan Lyon and Matt Tora(8423)
Robo-Advisor with Python by Aki Ranin(8365)